<% layout('/layouts/default.html', {title: '工人信息表管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('工人信息表管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btnSearch2" title="${text('修改状态')}">${text('修改状态')}</a>
				<a href="#" class="btn btn-default" id="btnSearch1" title="${text('查询条件删除')}">${text('查询条件删除')}</a>
				<% if(hasPermi('yl:ylWorker:edit')){ %>
					<a href="${ctx}/yl/ylWorker/form" class="btn btn-default btnTool" title="${text('新增工人信息表')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${ylWorker}" action="${ctx}/yl/ylWorker/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('工人姓名')}：</label>
					<div class="control-inline">
						<#form:input path="username" maxlength="50" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('工人年龄')}：</label>
					<div class="control-inline">
						<#form:input path="age" maxlength="3" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('工人状态，1表示在职，0表示离职')}：</label>
					<div class="control-inline width-120">
						<#form:select path="ylStatus" dictType="yl_worker_status" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('录用日期')}：</label>
					<div class="control-inline">
						<#form:input path="createTime" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("工人姓名")}', name:'username', index:'a.username', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/yl/ylWorker/form?id='+row.id+'" class="btnList" data-title="${text("编辑工人信息表")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("工人年龄")}', name:'age', index:'a.age', width:150, align:"left"},
		{header:'${text("工人状态，1表示在职，0表示离职")}', name:'ylStatus', index:'a.yl_status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('yl_worker_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("录用日期")}', name:'createTime', index:'a.create_time', width:150, align:"center"},
		{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){
			var actions = [];
			//<% if(hasPermi('yl:ylWorker:edit')){ %>
				actions.push('<a href="${ctx}/yl/ylWorker/form?id='+row.id+'" class="btnList" title="${text("编辑工人信息表")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/yl/ylWorker/delete?id='+row.id+'" class="btnList" title="${text("删除工人信息表")}" data-confirm="${text("确认要删除该工人信息表吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
				actions.push('<input type="checkbox" name="checknnnnn" data-id="' + row.id + '" class="checkccccc">&nbsp;');

			//<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
/*-----------------------------------------------------------------------------------------------------------------*/
var datalist = [];

document.addEventListener('DOMContentLoaded', function() {
	// 事件委托
	document.addEventListener('change', function(event) {
		if (event.target.classList.contains('checkccccc')) {
			const rowId = event.target.getAttribute('data-id'); // 获取行数据

			if (event.target.checked) {
				// 如果复选框被勾选，将行数据添加到数组
				if (!datalist.includes(rowId)) {
					datalist.push(rowId);
					console.log('行 ID:', rowId, '已添加到数组');
				}
			} else {
				// 如果复选框被取消勾选，将行数据从数组中删除
				const index = datalist.indexOf(rowId);
				if (index !== -1) {
					datalist.splice(index, 1);
					console.log('行 ID:', rowId, '已从数组中删除');
				}
			}

			// 打印当前数组内容
			console.log('当前数组:', datalist);
		}
	});
});

$('#btnSearch2').click(()=>{

	$.ajax({
		url:'${ctx}/yl/ylWorker/updateStatus',
		type:'POST',
		contentType: 'application/JSON',
		data:JSON.stringify(datalist)
	}).then(result=>{
		alert(result);
	}).always(()=>{
		$('#dataGrid').dataGrid('reloadGrid');
		datalist = [];
	})
});























$('#btnSearch1').click(function (){
	deleteBtn();
})
function deleteBtn() {
	let dataGrid = $('#dataGrid').dataGrid('getDataIDs');
	$.ajax({
		url:'${ctx}/yl/ylWorker/deleteList',
		type: 'POST',
		contentType: 'application/json',
		data: JSON.stringify(dataGrid)
	})
	.then(result=>{
		alert(result);
	})
	.always(()=>{
		$('#dataGrid').dataGrid('reloadGrid');
	})
};









</script>